message(${CMAKE_SOURCE_DIR}/bin)
execute_process(
	COMMAND	dpkg --print-architecture
    OUTPUT_VARIABLE CMAKE_HOST_ARCH
)
string (REGEX REPLACE "[\n\t\r]" "" CMAKE_HOST_ARCH ${CMAKE_HOST_ARCH})
if(${CMAKE_HOST_ARCH} STREQUAL "amd64")
    set(HOST_ARCH "x64")
elseif(${CMAKE_HOST_ARCH} STREQUAL "i386")
    set(HOST_ARCH "x86")
else()
    message(FATAL_ERROR "Unsupported architecture ${CMAKE_HOST_ARCH}")
endif()
message("Build architecture is ${HOST_ARCH}")
set(CMAKE_CXX_STANDARD 20)

if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
    set(CMAKE_INSTALL_RPATH "${CMAKE_SOURCE_DIR}/${HOST_ARCH}/lib")
    # set(CMAKE_INSTALL_RPATH "/usr/etc/jkzuc/bin")
else()
	set(CMAKE_INSTALL_RPATH "/usr/etc/jkzuc/bin")
endif()

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
set(c_cxx_flags "-fPIC -fno-strict-aliasing -DULAPI -Wall -Werror -Wno-format-truncation -Wno-format-overflow -Wno-comment -Wno-unused-variable -Wno-parentheses -Wno-unused-function -Wno-unused-but-set-variable")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${c_cxx_flags}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${c_cxx_flags} -Wno-register -Wno-class-memaccess")
set(DEBUG_FLAG "-D_DEBUG -g")
# set(DEBUG_FLAG "-D_DEBUG -fprofile-arcs -ftest-coverage -g")
set(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -O0 ${DEBUG_FLAG}")
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 ${DEBUG_FLAG}")

# FIXME: -O0 is for debugging, remove it when release
set(CMAKE_C_FLAGS_RELEASE "$ENV{CFLAGS} -O0 -g")
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O0 -g")
# set(CMAKE_C_FLAGS_RELEASE "$ENV{CFLAGS}")
# set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS}")
